<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>数据权限管理</title>
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
	</head>

	<body>
	<div class="wrap-container clearfix">
		<div class="column-content-detail">
			<form class="layui-form">
				<div class="search-cont clearfix" id="tool">
					<div class="operation-btn-cont">
						<div class="operright cyt-retract-close hideRule">
							收起筛选<i class="iconfont">&#xe658;</i>
						</div>
						<div class="operright cyt-retract-open showRule" style="display: none;">
							展开筛选<i class="iconfont">&#xe936;</i>
						</div>
						<@shiro.hasPermission name="sys:rule:add">
						<button class="layui-btn layui-btn-normal layui-btn-mid" type="button" data-tab-name="添加"  id="ruleAddOrEdit" ><i class="iconfont marr5">&#xe65e;</i>添加</button>
						</@shiro.hasPermission>
						<button class="layui-btn layui-btn-normal layui-btn-mid up-all" type="button" ><i class="iconfont marr5">&#xe66f;</i>收起</button>
						<button class="layui-btn layui-btn-normal layui-btn-mid down-all" type="button"><i class="iconfont marr5">&#xe6a6;</i>展开</button>

					<div class="triangle-bottom"></div>
			<div class="triangle-top"></div>
			</div>
			<div class="search-details">
					<div class="layui-form-item marb5">
						<div class="layui-inline">
							<label class="layui-form-label w75">名称：</label>
							<div class="layui-input-inline">
								<input type="text" name="name" id="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label w75">code：</label>
							<div class="layui-input-inline">
								<input type="text" name="code" id="code" placeholder="请输入Code" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label w75">标识符：</label>
							<div class="layui-input-inline">
								<input type="text" name="permission" id="permission" placeholder="请输入标识符" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline marl8">
							<button class="layui-btn layui-btn-normal" type="button" lay-submit="" id="seacherBtn">搜索</button>
							<button class="layui-btn layui-btn-normal" type="reset" >重置</button>
						</div>
					</div>
			</div>
			</form>
			<div class="layui-form" id="table-list">
				<table lay-filter="entityList" class="layui-table layui-formcy-list-table" id="test-tree-table"></table>
			</div>
	</div>
	</div>
	<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script>
        layui.use(['jquery','treetable','form','baseutil','page'],function(){
            var $ = layui.jquery,baseutil = layui.baseutil;
            var treetable = layui.treetable;
            var page = layui.page;
            var form = layui.form,layer = layui.layer;
            page.initDict("rule_type", function (dictData) {
                page.showDict($("#type"), page.aceeptDictContentList(dictData, "rule_type"), "请选择类型");
            	var renderTable =function () {
					var name=$('#name').val();
					var code=$('#code').val();
					var type=$('#type').val();
                    baseutil.post("/sysRule/list",{"name":name,"code":code,"type":type},function (result) {
                        var data=[];
                        if(0==result.code){
                            for(var i=0;i<result.data.length;i++){
                                var obj=result.data[i];
                                var d={};
                                d.id=obj.id;
                                d.name=obj.name;
                                if(obj.parentId==null||obj.parentId==""||(name!=null&&name!="")||(code!=null&&code!="")||(type!=null&&type!="")){
                                    d.pid=0;
                                }else{
                                    d.pid=obj.parentId;
                                }
                                d.url=obj.ruleUrl;
                                d.grade=obj.grade;
                                d.sort=obj.sort;
                                d.code=obj.code;
                                d.sqlContent=obj.sqlContent;
                                d.permission=obj.permission;
                                d.type=obj.type;
                                d.typeValue=page.aceeptDictContentName(dictData,"rule_type",obj.type);
                                data.push(d);
                            }
                            treetable.render({
                                elem: '#test-tree-table',
                                data:data,
                                field: 'name',
                                is_checkbox: true,
                                cols: [
                                    {
                                        field: 'name',
                                        title: '名称',
                                        width: '15%'
                                    },{
                                        field: 'grade',
                                        title: '级别',
                                        width: '7%'
                                    },{
                                        field: 'sort',
                                        title: '排序',
                                        width: '7%'
                                    },{
                                        field: 'code',
                                        title: 'code',
                                        width: '11%'
                                    },{
                                        field: 'typeValue',
                                        title: '类型',
                                        width: '10%'
                                    },{
                                        field: 'permission',
                                        title: '标识符',
                                        width: '15%'
                                    },{
                                        field: 'sqlContent',
                                        title: '条件语句',
                                        width: '20%'
                                    },{
                                        title: '操作',
                                        width: '15%',
                                        template: function(data){
                                            var tem = [];
                                            if(data.type=="1"){
                                                tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-purple"  lay-filter="add">添加</a>');
											}
                                            tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green"  lay-filter="edit">编辑</a>');
                                            tem.push('<button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-filter="delete">删除</button>');
                                            return tem.join(' <font> </font> ')
                                        },
                                    }
                                ]
                            });
                        }else{
                            top.layer.msg(result.msg);
                        }
                    });
                    treetable.on('treetable(add)',function(data){
                        page.editPopup("/sysRule/getAddOrEdit?parentId="+data.item.id,"添加");
                        console.dir(data);
                    });

                    treetable.on('treetable(edit)',function(data){
						var parentId="";
                        if(data.item.pid!=0){
                            parentId=data.item.pid;
						}
                        page.editPopup("/sysRule/getAddOrEdit?id="+data.item.id+"&parentId="+parentId,"编辑");
                        console.dir(data);
                    });
                    treetable.on('treetable(delete)',function(data){
                        page.delete("/sysRule/delete", {"id":data.item.id,"_method":"DELETE"},"确定删除吗？",function (data) {
                            top.layer.msg(data);
                            renderTable();
                        });
                    });

                    //监听行工具事件
                    treetable.on('tool(test-tree-table)', function(obj){
                        var layEvent = obj.event,
                            data = obj.data;
                        if(layEvent === 'del'){ //删除
                            page.delete("/sysRule/delete", {"id":data.item.id,"_method":"DELETE"},"确定删除吗？",function (data) {
                                top.layer.msg(data);
                                renderTable();
                            });
                        }
                    });

                    form.on('switch(status)',function(data){
                        layer.msg('监听状态操作');
                        console.dir(data);
                    })
                };

            renderTable();
            $('#seacherBtn').click(function(){
                renderTable();
            });

            $('.up-all').click(function(){
                treetable.all('up');
            });

            $('.down-all').click(function(){
                treetable.all('down');
            });

            $('.get-checked').click(function(){
                console.dir(treetable.all('checked'));
            });

        });
            $("#ruleAddOrEdit").bind("click",function () {
                page.editPopup("/sysRule/getAddOrEdit","添加");
            });
        });
	</script>
	</body>

</html>